<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">矛盾纠纷类型:</div>
        <div class="input-item">
          <a-select ref="select" v-model="queryParam.disputesType" placeholder="请选择">
            <a-select-option v-for="(item, index) in disputes_type" :key="index" :value="item.value">
              {{ item.text }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">所属辖区:</div>
        <div class="input-item">
          <a-select
            ref="select"
            show-search
            placeholder="请选择辖区"
            v-model="queryParam.policeJurisdictionId"
            :filter-option="filterOption"
          >
            <a-select-option :value="item.id" v-for="(item, index) in police_list" :key="index">{{
              item.jurisdictionName
            }}</a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">创建时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">是否进一步调解:</div>
        <div class="input-item">
          <a-select ref="select" v-model="queryParam.defuseStatus" placeholder="请选择">
            <a-select-option value="2">是</a-select-option>
            <a-select-option value="3">否</a-select-option>
          </a-select>
        </div>
      </div>

      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery(queryParam.startTime, queryParam.endTime)" type="primary">
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template #disputesType="record">
          <span> {{ get_dict_type(disputes_type, record.disputesType) }}</span>
        </template>
        <template #onDefuseStatus="record">
          <span> {{ record.onDefuseStatus == 1 ? '是' : '否' }}</span>
        </template>
        <template #disputesDefuse="record">
          <span> {{ record.userNames }} {{ get_dict_type(disputes_type, record.disputesType) }}</span>
        </template>
        <template v-slot:action="records">
          <span class="operation deatil-color" @click="show_adjustmentDetail(records)">详情 </span>
          <span class="operation deatil-color" @click="show_registration(records)">排查登记 </span>
          <span class="operation deatil-color" @click="show_adjustmentRecord(records)">调解记录 </span>
        </template>
      </a-table>
    </div>

    <adjustmentDetail ref="adjustmentDetail" />
    <registration ref="registration" />
    <adjustmentRecord ref="adjustmentRecord" />
  </div>
</template>
<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { mapState } from 'vuex'
import { ajaxGetDictItems } from '@/api/api'
import { getAction } from '@/api/manage'
import adjustmentDetail from './modules/adjustment_detailModal'
import registration from './modules/adjustment_registration'
import adjustmentRecord from './modules/adjustmentRecord'
export default {
  name: 'visitor-alreadyVisited',
  components: { startEndTime, adjustmentDetail, registration, adjustmentRecord },
  mixins: [JeecgListMixin],
  computed: {
    ...mapState({
      isPoliceAgencyId: (state) => state.user.isPoliceAgencyId,
    }),
  },
  watch: {
    isPoliceAgencyId: {
      handler(v) {
        this.queryParam.policeAgencyId = v.id ? v.id : ''
        this.searchQuery()
      },
    },
  },
  data() {
    return {
      url: {
        list: '/common/disputes_defuse/page',
        tree: true,
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '纠纷名称',
          // dataIndex: 'disputesDefuse',
          scopedSlots: { customRender: 'disputesDefuse' },
          ellipsis: true,
          width: 200,
          align: 'center',
        },
        {
          title: '类型',
          // dataIndex: 'clueType',
          scopedSlots: { customRender: 'disputesType' },
          ellipsis: true,
          align: 'center',
        },
        {
          title: '所属辖区',
          dataIndex: 'policeJurisdictionName',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '调解次数',
          dataIndex: 'defuseCount',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '是否进一步调解',
          scopedSlots: { customRender: 'onDefuseStatus' },
          ellipsis: true,
          align: 'center',
          width: 140,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          ellipsis: true,
          align: 'center',
          width: 180,
        },

        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          align: 'center',
          width: 300,
        },
      ],
      disableMixinCreated: true,
      disputes_type: [], // 线索类型
      police_list: [],
    }
  },
  mounted() {
    this.getDist()
    this.get_police_list()
  },
  methods: {
    async getDist() {
      let { result: disputes_type } = await ajaxGetDictItems({ code: 'disputes_type' })
      this.disputes_type = disputes_type
    },
    get_dict_type(list, type) {
      let res = list.find((item) => item.value == type)
      if (res && res.title) {
        return res.title
      } else {
        return '暂无'
      }
    },

    async get_police_list() {
      let { policeAgencyId } = JSON.parse(localStorage.getItem('pro__Login_Userinfo')).value
      let {
        result: { records },
      } = await getAction('/police/jurisdiction/list', { policeAgencyId, pageSize: 99999 })

      this.police_list = records.map((item) => ({
        id: item.id,
        jurisdictionName: item.jurisdictionName,
        principalPoliceUser: item.principalPoliceUser ? item.principalPoliceUser.name : '暂无',
      }))
    },

    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.startTime = null
        this.queryParam.endTime = null
      }
    },

    show_adjustmentDetail(records) {
      this.$refs.adjustmentDetail.show(records)
    },
    show_registration(records) {
      this.$refs.registration.show(records)
    },
    show_adjustmentRecord(records) {
      this.$refs.adjustmentRecord.show(records)
    },

    filterOption(input, option) {
      return option.componentOptions.children[0].text.indexOf(input) >= 0
    },
  },
}
</script>
